<?php

	class Mod_winner extends CI_Model{

		function __construct()
		{
			parent::__construct();
		}

		function winner($id)
		{
			$query_str1 = "SELECT u_id FROM inscricoes WHERE g_id = $id ORDER BY RAND() LIMIT 1";
			$result1 = $this->db->query($query_str1);
			if ($result1->num_rows() > 0)
			{
			    $row = $result1->row(); 
			    $u_id = $row->u_id;

			   	$query_str3 = "UPDATE giveaway SET g_winner = $u_id WHERE g_id = $id";
			   	$result3 = $this->db->query($query_str3);
			}		
		}

	}

?>